from .celery import app


@app.task
def update_banner_list():
    from django.core.cache import cache
    from home import models, serializer
    from django.conf import settings
    queryset_banner = models.Banner.objects.filter(is_delete=False, is_show=True).order_by("orders")[
               :settings.BANNER_COUNTER]
    banner_list_ser = serializer.BannerModelSerializer(instance=queryset_banner, many=True)
    for banner in banner_list_ser.data:
        banner['img'] = "http://127.0.0.1:8000" + banner["img"]

    cache.set("banner_list", banner_list_ser.data)
    return True
